package com.atguigu.spzx.manager.controller.product;

import com.atguigu.spzx.manager.service.product.CategoryBrandService;
import com.atguigu.spzx.manager.service.product.ProductSpecService;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.product.CategoryBrandVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name="商品规格管理模块")
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {
    @Resource
    ProductSpecService productSpecService;
    @Operation(summary = "查询所有商品规格")
    @GetMapping("/findAll")// ?brandId=x&categoryId=x
    public Result findAll(){
        List<ProductSpec> list = productSpecService.findAll();
        return Result.ok().data(list);
    }

    @Operation(summary = "新增商品规格")
    @PostMapping("save")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.ok();
    }
    @Operation(summary = "删除商品规格")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Long id){
        productSpecService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "根据id查询商品规格")
    @GetMapping("{id}")
    public Result getById(@PathVariable("id")Long id){
        ProductSpec productSpec = productSpecService.getById(id);
        return Result.ok().data(productSpec);
    }
    @Operation(summary = "更新商品规格")
    @PutMapping("update")
    public Result update(@RequestBody ProductSpec productSpec){
        productSpecService.update(productSpec);
        return Result.ok();
    }


    @Operation(summary = "查询商品规格分页数据")
    @GetMapping("page/{pageNum}/{pageSize}")// ?brandId=x&categoryId=x
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize){
        PageInfo<ProductSpec> pageInfo = productSpecService.page(pageNum,pageSize);
        return Result.ok().data(pageInfo);
    }
}
